package com.lj.syn.test;

import com.lj.syn.thread.AbstractSyn;
import com.lj.syn.thread.ThreadTestAA;
import com.lj.syn.thread.ThreadTestCC;

/**
 * 多线程下调用不同方法，并发问题
 *
 * 求：打印顺序
 * Created by yangsp1 on 16/3/27.
 */
public class SynCommon extends AbstractSyn {
    /**
     * 不同加锁方式测试：混合（加＼不加）
     * 方法加锁
     */
    public synchronized void aa() throws InterruptedException {
        for(int i = 0; i < 3; i++) {
            Thread.sleep(1000);
            System.out.println("我是aa");
        }

    }

    /**
     * 不加锁
     */
    public void cc() throws InterruptedException {
        for(int i = 0; i < 3; i++){
            Thread.sleep(1000);
            System.out.println("我是cc");
        }
    }


    public static void main(String args[]) throws Exception{
        AbstractSyn synTest = new SynCommon();
        Thread tA = new Thread(new ThreadTestAA(synTest));
        Thread tC = new Thread(new ThreadTestCC(synTest));
        tA.start();
        tC.start();
    }
}
